﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EnheimGallery.DAL
{
    public class PhotoInfoData
    {
        public string Name;
        public string Description;
    }
    public class PhotosDAL
    {
        public Photo CreatePhoto(string name, int categoryId, string description = "")
        {
            Photo newPhoto = new Photo()
            {
                Name = name,
                AddedDate = DateTime.Now,
                LastSeen = DateTime.Now,
                Description = description,
                CategoryId = categoryId,
            };
            return newPhoto;
        }

        public static void AddPhotoToUser(aspnet_Users user, Photo photo)
        {
            EnheimGalleryDatabaseEntities db = new EnheimGalleryDatabaseEntities();
            db.AddToPhotos(photo);
            db.SaveChanges();
            // here add the image file to the application filesystem
        }
        public static PhotoInfoData GetPhotoInfo(Photo photo)
        {
            PhotoInfoData info=new PhotoInfoData();
            info.Name=photo.Name;
            info.Description=photo.Description;
            return info;
        }
        public static void ModifyPhoto(Photo photo, string name, string description)
        {
            EnheimGalleryDatabaseEntities db = new EnheimGalleryDatabaseEntities();
            Photo modifiedPhoto = photo;
            modifiedPhoto.Name = name;
            modifiedPhoto.Description = description;
            db.DeleteObject(photo);
            db.AddToPhotos(modifiedPhoto);
            db.SaveChanges();
        }
       
        public static void DeletePhoto(Photo photo)
        {
            EnheimGalleryDatabaseEntities db = new EnheimGalleryDatabaseEntities();
            db.DeleteObject(photo);
            //also delete from filesystem
        }

    }
}
